# /api/v1.0/houses/[int:house_id]
class HouseDetaView(View):
    def get(self, request, house_id):
        try:

            huse = House.objects.get(id = house_id)
            facilities = []
            for facility in house.facility.all():
                facilities.append(facility.id)

            orders = house.order_set.all()
            comments = []
            for order in orders:
                comments.append({
                    'comment': order.comment,
                    'ctime': order.create_time,
                    'username': order.user.username,
                })

            img_urls = []
            house_image = HouseImage.objects.filter(house_id = house_id)
            print(len(house_image))
            for img in house_image:
                img_urls.append("http://qjq2idd98.hd-bkt.clouddn.com/" + img.url)
        except Exception as e:
            return JsonResponse({
                'errmsg': '请求失败',
                'errno': '400'
            })
        print('88888888')
        return JsonResponse({
            'data': {
                'house': {
                    "acreage": house.acreage,
                    "address": house.address,
                    "beds": house.beds,
                    "capacity": house.capacity,
                    'comments': comments,
                    'deposit': house.deposit,
                    "facilities": facilities,
                    'hid': house.id,
                    'img_urls': img_urls,
                    'max_days': house.max_days,
                    'min_days': house.min_days,
                    'price': house.price,
                    'room_count': house.room_count,
                    'title': house.title,
                    'unit': house.unit,
                    'user_avatar': "http://qjq2idd98.hd-bkt.clouddn.com/" + house.user.avatar.name,
                    'user_id': house.user.id,
                    'user_name': house.user.username
                },
                'user_id': house.user.id
            },
            'errmsg': 'OK',
            'errno': '0'
        })